import Taro, { Component } from '@tarojs/taro'
import { toHomePage } from "@/utils/page_router"
import { APP_SYSTEM_INFO } from "@/config/config"

const { capsule, navBarHeight, statusBarHeight } = APP_SYSTEM_INFO
export default class FyComponent<P = {}, S = {}> extends Component<P, S> {
  state: any
  props: any

  static options = {
    addGlobalClass: true
  }

  constructor() {
    super(...arguments)
    this.state = {
      capsule,
      navBarHeight,
      statusBarHeight
    }
  }

  //  返回上一页面
  onNavigateBack () {
    const pages = Taro.getCurrentPages()
    if (pages.length === 1) {
      toHomePage()
    } else {
      Taro.navigateBack()
    }
  }

  //  返回首页
  onNavigateHome () {
    toHomePage()
  }
}
